package com.by;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author ServivE
 * @version 0.1
 * @className Consumer
 * @description
 * @date 2024/10/23 10:06
 * @since jdk17
 */
@Component
public class Consumer {

    @RabbitListener(queues = {"error"})
    public void handlerError(Message message, Channel channel) throws IOException {
        System.out.println("error:" + new String(message.getBody()));
        //手动应答
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

    @RabbitListener(queues = {"info"})
    public void handlerInfo(Message message,Channel channel) throws IOException {
        System.out.println("info:" + new String(message.getBody()));
        //拒绝应答  不重新入队
        channel.basicNack(message.getMessageProperties().getDeliveryTag(), false,false);
    }
}
